package cn.cdeden.knowledge.domain;

//import io.swagger.annotations.ApiModelProperty;
import cn.cdeden.resource.api.domain.RemoteFilesDownload;
import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.AutoMappers;
import io.github.linpeilie.annotations.AutoMapping;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @ProjectName : ecm_svn02
 * @Package : com.cdyd.ecm.utils
 * @ClassName : TreeFilesDto
 * @Author : Yu.
 * @Description : // 文件下载树的处理
 * @Date : 2023/11/20 16:55
 * @Version : 1.0
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class TreeDownloadFiles {

//    @ApiModelProperty(value = "文件id")
    private Long id;

//    @ApiModelProperty(value = "团队编号")
    private String teamId;

//    @ApiModelProperty(value = "上级的编号")
    private String superiorsIds;

//    @ApiModelProperty(value = "父亲节点编号")
    private String parentId;

//    @ApiModelProperty(value = "名称")
    private String realName;

//    @ApiModelProperty(value = "后缀名")
    private String suffix;

//    @ApiModelProperty(value = "类型")
    private String type;

//    @ApiModelProperty(value = "储存表id")
    private String storageId;

//    @ApiModelProperty(value = "储存服务器类型")
    private String storageType;

//    @ApiModelProperty(value = "文件大小")
    private Long size;

//    @ApiModelProperty(value = "库的类型")
    private String  libraryType;

//    @ApiModelProperty(value = "版本号")
    private String edition;

//    @ApiModelProperty(value = "版本编码")
    private String editionName;

//    @ApiModelProperty(value = "下载文件地址")
    private String downloadPath;

//    @ApiModelProperty(value = "创建编号")
    private String createId;

//    @ApiModelProperty(value = "创建者")
    private String createBy;

//    @ApiModelProperty(value = "创建日期")
    private Date createTime;

//    @ApiModelProperty(value = "更新编号")
    private String updateId;

//    @ApiModelProperty(value = "更新者")
    private String updateBy;

//    @ApiModelProperty(value = "更新时间")
    private Date updateTime;

//    @ApiModelProperty(value = "儿子数据")
    private List<TreeDownloadFiles> children = new ArrayList<>();



    /**
     * @author Yu.
     * @Description // list 转 树结构
     * @Date 2023/11/22 15:09
     * @param filesTrees
     * @param ids
     * @param libraryType
     * @return java.util.List<com.cdyd.ecm.domain.TreeDownloadFiles>
     **/
    public static  List<TreeDownloadFiles> listToTerr(List<TreeDownloadFiles> filesTrees ,List<String> ids,String libraryType){
        if (CollectionUtils.isEmpty(filesTrees) || CollectionUtils.isEmpty(ids)){
            return  new ArrayList<>();
        }

        filesTrees.forEach(tree -> tree.setLibraryType(libraryType) ); //设置库的类型
        Map<String, List<TreeDownloadFiles>> collect = filesTrees.stream().collect(Collectors.groupingBy(TreeDownloadFiles::getParentId));
        for (TreeDownloadFiles filesTree : filesTrees) {
            String of = String.valueOf(filesTree.getId());
            List<TreeDownloadFiles> files = collect.get(of);
            filesTree.setChildren(files);
        }

        return filesTrees.stream().filter(downloadFiles -> ids.contains(downloadFiles.getId().toString())).collect(Collectors.toList());
    }

}
